﻿using MiniExcelLibs;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂.仓库.报表
{
    public partial class Form成品卷状态查询 : UIPage
    {
        public Form成品卷状态查询()
        {
            InitializeComponent();
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            查询();
        }

        private DataTable 查询()
        {
            string sql = "SELECT   [WorkLine] 产线,      [PingMing] 品名,  [VolumeCodeNew] 批号  ,   [WarehouseCode] 仓库 ,StorageLocation 库位    ,[ProductDate] 生产日期  ,[Size] 规格    ,[Weight] 重量           ,[Grade] 等级  ,[Meter] 长度      ,[ZinCeng] 锌层      ,[PackageType] 包装形式      ,[Customer] 客户      ,[Color] 颜色 FROM [Bus_StockInVolume]";
            sql += "where VolumeCodeNew like '%" + uiTextBox卷号.Text.Trim() + "%'";
            DataTable dt = pub.GetDataTable(pub.ConnectionString, sql);
            uiDataGridView1.DataSource = dt;
            uiDataGridView1.Refresh();
            return dt;
        }

        private void uiButton导出_Click(object sender, EventArgs e)
        {
            string path;
            this.saveFileDialog1.Filter = "Excel文件 (*.XLSX)|*.XLSX";
            if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                path = this.saveFileDialog1.FileName;
                if (!File.Exists(path))
                {
                    MiniExcel.SaveAs(path, 查询(), true, "sheet1", ExcelType.XLSX);
                }
                else
                {
                    MessageBox.Show("文件已经存在,请重试!", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }
    }
}
